home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sun Solutions 1997 April to September
/
Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso
/
products
/
Versant
/
stockquote.pl
< prev
next >
Wrap
Perl Script
|
1997-01-08
|
6KB
|
193 lines
#!/usr/local/bin/perl
$stkdir = "/www/versant/versant.v1";
chdir $stkdir;
$filesrc="tmpl.htm"; # This is the file you can edit.
$fileorig="stock.org"; # This is a semi-pristine copy.
$filedest="stock.htm"; # This is the result.
$quote = "vsnt";
#print "Getting info\n";
$stock = `/www/versant/quote/quote $quote`;
($Symbol,$Date,$Time,$Open,$High,$Low,$Last,$Change,$Volume) = split(/\t/,$stock);
($Market,$Symbol) = split (/:/, $Symbol);
$Prev = $Last - $Change;
$Last = &makefraction ($Last);
$Prev = &makefraction ($Prev);
$Open = &makefraction ($Open);
$High = &makefraction ($High);
$Low = &makefraction ($Low);
$Change = &makefraction ($Change);
$Volume = &makefraction ($Volume);
#print "Making Table\n";
$table = "<TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0><TR><TD>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR=9a9a9a>
<TR>
<TH ALIGN=left><FONT COLOR=ffffff SIZE=-1>Symbol</FONT></TH>
<TH ALIGN=CENTER><FONT COLOR=ffffff SIZE=-1>Last</FONT></TH>
<TH ALIGN=CENTER><FONT COLOR=ffffff SIZE=-1>Change</FONT></TH>
<TH ALIGN=CENTER><FONT COLOR=ffffff SIZE=-1>Previous</FONT></TH>
<TH ALIGN=CENTER><FONT COLOR=ffffff SIZE=-1>Low</FONT></TH>
<TH ALIGN=CENTER><FONT COLOR=ffffff SIZE=-1>High</FONT></TH>
<TH ALIGN=right><FONT COLOR=ffffff SIZE=-1>Volume</FONT></TH>
</TR>
<TR BGCOLOR=6699CC>
<TD ALIGN=LEFT><B><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$Symbol</FONT></B></TD>
<TD ALIGN=CENTER><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$Last</FONT></TD>
<TD ALIGN=CENTER><FONT FACE=ARIAL,HELVETICA COLOR=red SIZE=-1>$Change</FONT></TD>
<TD ALIGN=CENTER><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$Prev</FONT></TD>
<TD ALIGN=CENTER><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$Low</FONT></TD>
<TD ALIGN=CENTER><B><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$High</FONT></B></TD>
<TD ALIGN=RIGHT><FONT FACE=ARIAL,HELVETICA COLOR=000000 SIZE=-1>$Volume</FONT></TD>
</TR>
</TABLE>
</TD></TR>
</TABLE>
</CENTER>";
$sof = "$Date @ $Time ET";
#print "Updating File\n";
&updatefile ($table,$sof,1);
sub updatefile {
local($t,$d,$s) = ($_[0],$_[1],$_[2]);
local($intab,$nocmt,$copyback)=(0,0,0);
# Work with a safe 'original' copy of the file.
# This copy doesn't get modified by overwriting, limiting mutation.
if ( ! -e $fileorig ) {
if ( ! -e $filesrc ) {
return -1;
} else {
©file ($filesrc, $fileorig);
}
} elsif ( -e $filesrc && ( -M $fileorig > -M $filesrc ) ){
©file ($filesrc, $fileorig);
}
# If we don't have a target file yet, at all, use the original.
if ( $s <= 0 ) {
if ( ! -e $filedest ) {
©file ($fileorig, $filedest);
} elsif ( -e $fileorig && ( -M $filedest > -M $fileorig ) ){
©file ($fileorig, $filedest);
}
return -2;
}
open (HTML,"<" . $fileorig);
open (NHTML,">" . $filedest);
$ret = "\r"; # For when it's needed. Puzzling to me.
$ret = "\n"; # For when it's needed. Puzzling to me.
$\ = ""; # This could be made "\r" to be more
while (<HTML>) {
if ( $nocmt == 0 && m/<!-- Okay, you can change stuff after/io ) {
$intab = 2 ;
}
if ( $usefallback == 1 && $intab == 0 && m/<table/io) {
$intab == 0;
} elsif ( $intab != 1) {
# Normal copy behavior.
print NHTML $_;
}
if ( $nocmt == 1 && m/<!-- Okay, you can change stuff after/io ) {
# This is abnormal; orig has '<!--' ending comment only.
$intab = 4 ;
}
if ( m/<!-- Do not change: table is auto-inserted/io ) {
# This is normal; orig has '<!--' comments.
$intab = 1 ;
if ($s == 1) { # got as "table" succeeded
&dumptable($t,$d,$ret);
}
$copyback=0;
}
if ( $intab == 1 && $s == 2 ) {
&evalline($_);
}
if ($nocmt == 1 && $intab == 1 && m/As of:/io) {
# This is acceptable; orig has no opening '<!--' comment.
$intab = 3;
}
if ( $usefallback == 1 && $intab == 0 && m/<table/io) {
# This is acceptable if $usefallback == 1;
# orig has no opening '<!--' comment.
$nocmt = 1;
$intab = 1;
print NHTML "<!-- Do not change: table is auto-inserted-->" . $ret;
&dumptable($t,$d,$ret);
print NHTML "<!-- Okay, you can change stuff after this-->" . $ret;
$copyback=1;
}
}
close HTML;
close NHTML;
if ($usefallback == 1 && $copyback == 1) {# Original needs '<!--'
# comments, so copy file.
©file ($fileorig,"C" . $fileorig);
©file ($filedest, $fileorig);
}
return 0;
}
sub dumptable {
local($t,$d,$ret) = ($_[0],$_[1],$_[2]);
print NHTML $t . $ret ;print NHTML "";
print NHTML "<center>" . $ret ;print NHTML "";
print NHTML "<br>" . $ret ;print NHTML "";
print NHTML "<font size=2><i>Stock price as of: " . $d . "</i></font></center>" . $ret ;print NHTML "";
}
sub makefraction {
local ($int,$dec) = split (/\./,$_[0]);
local $num;
local $bot;
$bot =10000;
if ($dec != 0) {
while ($dec < 1000) { $dec *= 10; }
while ($dec%5 == 0 && $bot%5 == 0 ) {
$bot /= 5;
$dec /= 5;
}
while ($dec%2 == 0 && $bot%2 == 0) {
$bot /= 2;
$dec /= 2;
}
$num = $int." ".$dec."/".$bot;
} else { $num = $int; }
# print "$num\n";
$num;
}
sub copyfile {
local ($src,$dest) = ($_[0],$_[1]);
open (SRC,"<$src") || return -1;
open (DEST,">$dest") || return -2;
while (<SRC>) {
printf DEST "%s",$_;
}
close SRC;
close DEST;
return 0;
}